package cn.edu.cug.cs.gtl.docsrv.raw.dao.impl;

import cn.edu.cug.cs.gtl.docsrv.Managers;
import cn.edu.cug.cs.gtl.docsrv.raw.catalog.CatalogTree;
import cn.edu.cug.cs.gtl.docsrv.raw.dao.RawDao;
import cn.edu.cug.cs.gtl.docsrv.raw.manager.RawManager;
import cn.edu.cug.cs.gtl.mybatis.mapper.raw.RawAll;
import cn.edu.cug.cs.gtl.mybatis.mapper.raw.RawCatalog;
import cn.edu.cug.cs.gtl.mybatis.mapper.raw.RawItem;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.List;

@Component
public class RawDaoImpl implements RawDao {
    RawManager rawManager =null;

    @Override
    public CatalogTree getCatalogTree() {
        if(rawManager==null)
            rawManager= Managers.getRawManager();
        return rawManager.getCatalogTree();
    }

//    @Override
//    public RawAll getRawByInternalId(BigDecimal rawInternalId) {
//        if(rawManager==null){
//            rawManager=Managers.getRawManager();
//        }
//        RawAll rawAll = rawManager.queryByInternalId(rawInternalId);
//        return rawAll;
//    }
    @Override
    public List<RawItem> getRawByInternalId(BigDecimal rawInternalId) {
        if(rawManager==null){
            rawManager=Managers.getRawManager();
        }
        List<RawItem> rawItem = rawManager.queryItemByInternalId(rawInternalId);
        return rawItem;
    }

    @Override
    public boolean addRaw(RawAll rawAll) {
        if(rawManager==null)
            rawManager=Managers.getRawManager();
        return rawManager.insert(rawAll);
    }

    @Override
    public void addRawCatalog(RawCatalog rawCatalog) {
        if(rawManager==null)
            rawManager=Managers.getRawManager();
        rawManager.insert(rawCatalog);
    }

    @Override
    public void updateRawData(RawAll rawAll) {
        if(rawManager==null)
            rawManager=Managers.getRawManager();
        rawManager.update(rawAll);
    }
}
